package com.enums;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

public enum ProcessStatus {


    NEW("NEW", "新创建"),
    RUNNING("RUNNING", "运行中"),
    TERMINATED("TERMINATED", "被终止"),
    COMPLETED("COMPLETED", "完成");

    private String code;
    private String text;

    ProcessStatus(String code, String text) {
        this.code = code;
        this.text = text;
    }

    public String code() {
        return this.code;
    }

    public String text() {
        return this.text;
    }

    private static final Map<String, String> codeMap = new HashMap<String, String>();
    static {
        for (ProcessStatus item : values()) {
            codeMap.put(item.code(), item.text());
        }
    }

    /**
     * 获取名称
     * 
     * @param code
     * @return
     */
    public static String getText(String code) {
        if (codeMap.containsKey(code)) {
            return codeMap.get(code);
        }
        return StringUtils.EMPTY;
    }

    public static boolean contains(String code) {
        if (StringUtils.isEmpty(code)) {
            return false;
        }
        return codeMap.containsKey(code);
    }

    public String getText() {
        if (codeMap.containsKey(code)) {
            return codeMap.get(code);
        }
        return StringUtils.EMPTY;
    }

}
